home *** CD-ROM | disk | FTP | other *** search
/ Super PC 34 / Super PC 34 (Shareware).iso / spc / UTIL / DJGPP2 / V2 / DJLSR200.ZIP / src / libc / posix / unistd / dup2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-26  |  514 b   |  27 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <unistd.h>
  4. #include <dpmi.h>
  5. #include <errno.h>
  6. #include <io.h>
  7. #include <libc/dosio.h>
  8.  
  9. int
  10. dup2(int fd, int newfd)
  11. {
  12.   __dpmi_regs r;
  13.   if (fd == newfd)
  14.     return newfd;
  15.   r.h.ah = 0x46;
  16.   r.x.bx = fd;
  17.   r.x.cx = newfd;
  18.   __dpmi_int(0x21, &r);
  19.   if (r.x.flags & 1)
  20.   {
  21.     errno = __doserr_to_errno(r.x.ax);
  22.     return -1;
  23.   }
  24.   setmode(newfd, __file_handle_modes[fd]);
  25.   return newfd;
  26. }
  27.